//
//  UserPageView.m
//  BGM
//
//  Created by liuqin on 2018/11/27.
//  Copyright © 2018年 com.alirtc.demo. All rights reserved.
//

#import "UserPageView.h"
#import "Common.h"
@implementation UserPageView

-(instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if (self != nil) {
        self.headImage = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREENW/3, SCREENW/3)];
        [self.headImage setBackgroundImage:[UIImage imageNamed:@"carmehead"] forState:UIControlStateNormal];
        self.headImage.center = CGPointMake(SCREENW/2, SCREENH/4);
        self.headImage.tag = 98;
        self.headImage.layer.masksToBounds = YES;
        self.headImage.layer.cornerRadius =(SCREENW/3)/2;
        [self addSubview:self.headImage];
        
        self.iphoneView = [[BGMTextView alloc]initWithFrame:CGRectMake(30, SCREENH/2-50, SCREENW-60, 50)];
        [self.iphoneView.iconImage setImage:[UIImage imageNamed:@"resName"]];
        self.iphoneView.myText.placeholder = @"请输入真实姓名";
        self.iphoneView.myText.returnKeyType = UIReturnKeyDone;
        self.iphoneView.myText.delegate = self;
        [self addSubview:self.iphoneView];
        float y = self.iphoneView.frame.origin.y + self.iphoneView.frame.size.height;
        self.cordView = [[BGMTextView alloc]initWithFrame:CGRectMake(30, y+25, SCREENW-60, 50)];
        [self.cordView.iconImage setImage:[UIImage imageNamed:@"shengri"]];
        self.cordView.myText.placeholder = @"生日";
        self.cordView.rightBtn.hidden = NO;
        self.cordView.rightBtn.backgroundColor = [UIColor clearColor];
        self.cordView.rightBtn.imageEdgeInsets = UIEdgeInsetsMake(0,30,0,0);
        [self.cordView.rightBtn setImage:[UIImage imageNamed:@"gengduo"] forState:UIControlStateNormal];
        [self addSubview:self.cordView];
        UIButton *birthbtn = [[UIButton alloc]initWithFrame:CGRectMake(self.cordView.frame.origin.x, self.cordView.frame.origin.y, self.cordView.frame.size.width, self.cordView.frame.size.height)];
        [self addSubview:birthbtn];
        birthbtn.backgroundColor = [UIColor clearColor];
        [birthbtn addTarget:self action:@selector(clickBirth) forControlEvents:UIControlEventTouchUpInside];
        
        
        y = self.cordView.frame.origin.y+self.cordView.frame.size.height;
        
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(30, y+25, SCREENW/2-30, 30)];
        [btn setImage:[UIImage imageNamed:@"resSex"] forState:UIControlStateNormal];
        [btn setTitle:@"选择您的性别" forState:UIControlStateNormal];
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, -50, 0, 0);
        [btn setTitleColor:bgmColor(155, 155, 155) forState:UIControlStateNormal];

        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:btn];
        
        
        self.sex1 = [[UIButton alloc]initWithFrame:CGRectMake(SCREENW/2, y+25, SCREENW/2/3, 30)];
        [self.sex1 setTitle:@"男生" forState:UIControlStateNormal];
        [self.sex1 setTitleColor:bgmColor(155, 155, 155) forState:UIControlStateNormal];
        self.sex1.layer.cornerRadius = 6;
        self.sex1.layer.masksToBounds = YES;
        self.sex1.titleLabel.font = [UIFont systemFontOfSize:14];
        self.sex1.tag = 99;;
        [self addSubview:self.sex1];
        
        self.sex2 = [[UIButton alloc]initWithFrame:CGRectMake(self.sex1.frame.origin.x+self.sex1.frame.size.width+20, y+25, SCREENW/2/3, 30)];
        [self.sex2 setTitle:@"女生" forState:UIControlStateNormal];
        [self.sex2 setTitleColor:bgmColor(155, 155, 155) forState:UIControlStateNormal];
        self.sex2.layer.cornerRadius = 6;
        self.sex2.layer.masksToBounds = YES;
        self.sex2.backgroundColor = [UIColor clearColor];
        self.sex2.titleLabel.font = [UIFont systemFontOfSize:14];
        self.sex2.tag = 100;
        [self addSubview:self.sex2];
        
        
        
        
        UIButton *nextBtn = [[UIButton alloc]initWithFrame:CGRectMake(50, SCREENH-150, SCREENW-80, 70)];
        [nextBtn setBackgroundImage:[UIImage imageNamed:@"loginSele"] forState:UIControlStateNormal];
        [self addSubview:nextBtn];
        nextBtn.tag = 101;
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, SCREENH-60, SCREENW, 20)];
        label.text = @"向上滑动 填写更多信息";
        label.font = [UIFont systemFontOfSize:13];
        label.textColor = bgmColor(155, 155, 155);
        label.textAlignment = NSTextAlignmentCenter;
        [self addSubview:label];
        
//        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, SCREENH-60, 20, 20)];
//        [imageView setImage:[UIImage imageNamed:@""]];
//        [self addSubview:imageView];
        
        
        
        [self.sex1 addTarget:self action:@selector(clickNext:) forControlEvents:UIControlEventTouchUpInside];
        [self.sex2 addTarget:self action:@selector(clickNext:) forControlEvents:UIControlEventTouchUpInside];
        [nextBtn addTarget:self action:@selector(clickNext:) forControlEvents:UIControlEventTouchUpInside];
        [self.headImage addTarget:self action:@selector(clickNext:) forControlEvents:UIControlEventTouchUpInside];

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenKeyBarod)];
        [self addGestureRecognizer:tap];
        self.userInteractionEnabled = YES;

    }
    return self;
}
- (void)hiddenKeyBarod{
    [self.iphoneView.myText resignFirstResponder];
    [self.cordView.myText resignFirstResponder];

}
- (void)clickBirth{
    [self.deleagte clickBrithView];
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
- (void)clickNext:(UIButton *)btn{
    int tag = (int)btn.tag;
    switch (tag) {
        case 98:   //选择头像
        {
            [self.deleagte seleHeadImage];
            
        }
            break;
        case 99:   //男生
        {
            [self.deleagte seleSex:tag];
            self.sex1.backgroundColor = bgmyelloeColor;
            self.sex2.backgroundColor = [UIColor clearColor];
            
        }
            break;
        case 100:  //女生
        {
            [self.deleagte seleSex:tag];
            self.sex2.backgroundColor = bgmyelloeColor;
            self.sex1.backgroundColor = [UIColor clearColor];
            
        }
            break;
        case 101:  //进入首面
        {
            [self.deleagte gotoNextVC];
            
        }
            break;
        default:
            break;
    }
}

//-(void)seleHeadImage;
//-(void)seleSex;
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
